<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<!--
    统计字符串中出现次数最多的字符是哪个，出现了几次  str = "abcdeereeryhhssqqq"
-->

<script>

    var str = 'abcdeereeryhhssqqq'

    function countStr(str) {
        var obj = {}
        //遍历字符串  获取每一个字符
        for (var i = 0; i < str.length; i++) {
            //  str[i]  相当于一个变量     对象.属性名   obj.str[i]   ->  obj[str[i]]  取值     obj.a = 1
            if (obj[str[i]]) {
                obj[str[i]]++
            } else {
                obj[str[i]] = 1
            }
        }
        var k;
        var max = -1

        //遍历对象    属性  for
        for (var key in obj) {
            if (max < obj[key]) {
                max = obj[key]
                k = key
            }
        }
        return k + ":" + max;
    }

    var s = countStr(str);
    console.log(s);
</script>
</body>
</html>